package leecode

type listNode19 struct {
	Val  int
	Next *listNode19
}

func removeNthFromEnd(head *listNode19, n int) *listNode19 {
	//创建一个虚拟头节点
	dummy := &listNode19{
		Next: head,
	}
	dummyhead := dummy
	slow := dummyhead //慢指针
	fast := dummyhead //快指针
	//让快指针先走n+1步
	for i := 0; i < n+1; i++ {
		fast = fast.Next
	}
	//快慢指针同时走 , 直到快指针为空
	for fast != nil {
		slow = slow.Next
		fast = fast.Next
	}
	slow.Next = slow.Next.Next
	return dummyhead.Next
}
